package com.desire.controller;

import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import java.util.Arrays;
import java.util.Map;


/**
 * @author LittleDesire
 * @description
 * @date 2022-04-20 周三 11:28
 * @since 17
 */
@Controller
// 将msg属性的值放入到session作用域当中
// 因为默认的属性值都存放到了request作用于当中
@SessionAttributes(value = "msg")
public class Student {
    @RequestMapping("student")
    @ResponseBody
    public String student(String username,String[]  hobby) {
        return username+" "+ Arrays.toString(hobby);
    }

    @RequestMapping("mv")

    public ModelAndView  mv() {
        ModelAndView mv = new ModelAndView();
        mv.addObject("msg", "ModelAndView mv");
        mv.setViewName("index");
        return mv;
    }

    @RequestMapping("m")
    public String  m(Model m) {
        m.addAttribute("m", "model");
        return "index";
    }

    @RequestMapping("map")
    public String  map(Map<String, Object> map) {
        map.put("mm", "我是map接值");
        return "index";
    }

    @RequestMapping("mp")
    public String  map(ModelMap mm) {
        mm.put("put", "put");
        mm.addAttribute("addr", "addr");
        return "index";
    }
}
